package step1;

import java.util.concurrent.atomic.AtomicLong;

public class Singleton {
    private volatile static Singleton instance;
    //AtomicLong是以原子方式操作long值的类，作用是保证并发时线程安全的累加
    private AtomicLong count = new AtomicLong(0);

   private Singleton(){};

   public static Singleton GetInstance() {
       if(instance == null) {
           synchronized (Singleton.class) {
               if(instance == null)
                   instance = new Singleton();
           }
       }
       return instance;
   }
    public AtomicLong getCount() {
        return count;
    }
    public void setCount() {
        count.addAndGet(1);
    }
}
